/**
 * @ Author: luoqi
 * @ Create Time: 2024-07-26 23:40
 * @ Modified by: luoqi
 * @ Modified time: 2025-03-10 23:03
 * @ Description:
 */

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <bsp.h>
#include "blink.h"
#include "../qshell/qterm.h"

static TX_THREAD task_blink;
static uint8_t task_blink_stack[256];
static void task_blink_hdl(uint32_t arg);

static QCliCmd cmd_blink;
static int cmd_blink_hdl(int argc, char **argv);

static uint32_t lfrq = 1000, hfrq = 1000;

static int blink_stat_set()
{
    
    return 0;
}

static void task_blink_hdl(uint32_t arg)
{
    UNUSED(arg);
    static bool state = false;

    while(1) {
        state = !state;
        if(state) {
            bsp_led_set(BSP_LED_OFF);
            tx_thread_sleep(hfrq);
        } else {
            bsp_led_set(BSP_LED_ON);
            tx_thread_sleep(lfrq);
        }
    }
}

int blink_init()
{
    qterm_attach(&cmd_blink, "blink", cmd_blink_hdl, "blink commands");
    return tx_thread_create(&task_blink, "blink",
        task_blink_hdl, 0, task_blink_stack, sizeof(task_blink_stack),
        1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
}

static int cmd_blink_hdl(int argc, char **argv)
{
   
    return 0;
}
